﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

using MyLibrary.Data.Builder;
using MyLibrary.Data.Builder.Config;

namespace MyLibrary.Data.Builder.Component
{
    class ConditionDateTime : ConditionComponentBase
    {

        private string _dbConnKey = String.Empty;
        /// <summary>
        /// 报表数据库的连接字符串键名
        /// </summary>
        public override string DBConnectionKey
        {
            get { return _dbConnKey; }
            set { _dbConnKey = value; }
        }

        private ReportCondition _condition = null;
        /// <summary>
        /// 下拉框中的数据源类型
        /// </summary>
        public override ReportCondition ReportCondition
        {
            get { return _condition; }
            set { _condition = value; }
        }

        /// <summary>
        /// 日期类型条件
        /// </summary>
        public ConditionDateTime()
        {
        }

        public override void DrawASPComponent(PlaceHolder holder)
        {
            Label label1 = new Label();
            Label label2 = new Label();
            TextBox txtDateFrom = new TextBox();
            TextBox txtDateTo = new TextBox();
            HtmlImage imgDateFrom = new HtmlImage();
            HtmlImage imgDateTo = new HtmlImage();

            imgDateFrom.Src = imgDateTo.Src = "images/datePicker.gif";
            imgDateFrom.Width = imgDateTo.Width = 16;
            imgDateFrom.Height = imgDateTo.Height = 22;
            imgDateFrom.Align = imgDateTo.Align = "absmiddle";
            imgDateFrom.Attributes.Add("onclick", "new WdatePicker({el:txtDateFrom})");
            imgDateTo.Attributes.Add("onclick", "new WdatePicker({el:txtDateTo})");

            label1.Text = "统计时间从：";
            txtDateFrom.ID = "txtDateFrom";
           
            label2.Text = "&nbsp;&nbsp;至&nbsp;&nbsp;";
            txtDateTo.ID = "txtDateTo";
            txtDateFrom.Width = txtDateTo.Width = 85;
            txtDateFrom.ReadOnly = txtDateTo.ReadOnly = true;

            txtDateFrom.Text = DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd");
            txtDateTo.Text = DateTime.Today.ToString("yyyy-MM-dd");

            holder.Controls.Add(label1);
            holder.Controls.Add(txtDateFrom);
            holder.Controls.Add(imgDateFrom);
            holder.Controls.Add(label2);
            holder.Controls.Add(txtDateTo);
            holder.Controls.Add(imgDateTo);
        }

        public override string DrawHTMLComponent()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("统计时间从： <input id='txtDateFrom' value='" + DateTime.Today.AddMonths(-1).ToString("yyyy-MM-dd") + "' style='width:85px;'/>")
                .Append(" <img onclick='new WdatePicker({el:txtDateFrom})' src='images/datePicker.gif' width='16' height='22' align='absmiddle' />")
                .Append(" &nbsp;到&nbsp;<input id='txtDateTo'value='" + DateTime.Today.ToString("yyyy-MM-dd") + "' style='width:85px;'/>")
                .Append(" <img onclick='new WdatePicker({el:txtDateFrom})' src='images/datePicker.gif' width='16' height='22' align='absmiddle' />");
            return builder.ToString();
        }
    }
}
